import Vue from 'vue'
import App from './App'
import router from './router'
import routers from './router/routers.js'

import '../static/css/reset.css';

import Video from 'video.js'
import 'video.js/dist/video-js.min.css';
Vue.prototype.$video=Video
window.videojs = Video
require('video.js/dist/lang/zh-CN.js')

//weui
import weui from 'weui.js'
import 'weui'
Vue.prototype.$weui = weui
//echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

import '../static/css/style.css';

//VueAwesomeSwiper
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css' //这里注意具体看使用的版本是否需要引入样式，以及具体位置。
Vue.use(VueAwesomeSwiper)

import { Base64 } from 'js-base64';
Vue.prototype.$base64 = Base64;

import Cookies from 'js-cookie';
import http from './service/httpAxios';

//全局loading组件
import Toast from '@/components/toast/toast'
Vue.use(Toast);
//全局gallery组件
import Gallery from '@/components/gallery/gallery'
Vue.use(Gallery);
//全局顶部组件
import myHeader from '@/components/Header.vue'
Vue.component('myHeader', myHeader)
//全局搜索组件
import searchBar from '@/components/searchBar.vue'
Vue.component('searchBar', searchBar)

import MescrollVue from 'mescroll.js/mescroll.vue'
import 'mescroll.js/mescroll.min.css'
Vue.component('mescroll-vue', MescrollVue);


import Grid from 'vue-js-grid'
Vue.use(Grid)
/*import Console from  'vconsole'
let vConsole=new Console();
Vue.use(vConsole);*/
//测试地址
let qiniuDomain = 'http://color.qzy.kim/';
let uploadServer = 'http://upload-z2.qiniup.com';
let isLocal = false;

// 正式地址
// let qiniuDomain = 'http://ban-file.boct-edu.com/';
// let uploadServer = 'http://upload-z2.qiniup.com';
// let isLocal = false;

Cookies.set("qiniuDomain", qiniuDomain);
Cookies.set("uploadServer", uploadServer);

Vue.prototype.qiniu = {
	domain: qiniuDomain,
	uploadServer: uploadServer,
	isLocal: isLocal
}
Vue.prototype.$Cookies = Cookies; //定义全局变量
Vue.prototype.$http = http; //定义全局变量

Vue.prototype.getMonthData = (a, b) => {
	//当月1号是周几
	let w = new Date(a, parseInt(b) - 1, 1).getDay();
	if (w == 0) w = 7;
	//第一个周一是几号
	let fw;
	if (w != 1) fw = 7 - w + 2;
	else fw = 1;

	// 当月总天数
	let td = new Date(a, parseInt(b), 0).getDate();

	//当月总共有几周
	let tw = Math.ceil((td - fw + 1) / 7);

	let dateList = []; //日期列表
	let weekList = []; //周列表
	for (let i = fw; i <= td; i++) {
		dateList.push(i)
	}
	for (let i = 0, len = dateList.length; i < len; i += 7) {
		weekList.push(dateList.slice(i, i + 7));
	}
	for (let i = 0; i < weekList.length; i++) {
		let fill = 7 - weekList[i].length;
		for (let m = 1; m <= fill; m++) {
			weekList[i].push(m)
		}
	}
	let config = {
		year: a, //年
		month: b, //月
		first_date_week: w, //当月1号是周几
		first_week_date: fw, //当月第一个周一是几号
		total_days: td, //当月总天数
		weekList: weekList, //周列表
	}
	return config
}

Vue.prototype.$search = {
	param: {
		search: '',
		current: 1, //当前页页码
		size: 20 //一页显示几条数据
	},
	handle: function() {
		this.param.size += 1;
	}
};

//全局方法-保存路由变量
Vue.prototype.$saveR = function(query) {
	this.$router.push({
		path: this.$route.path,
		query: query
	})
};
//全局方法-获取路由变量
Vue.prototype.$getR = function(param, defaultParam) {
	if (this.$route.query[param] || this.$route.query[param] == 0) {
		return this.$route.query[param]
	} else {
		return defaultParam
	}
};

Vue.prototype.$unique = function(arr1, arr2) {
	if (arr1.length == 0 && arr2.length == 0) return []
	else if (arr1.length == 0 && arr2.length != 0) return arr2
	else if (arr1.length1 = 0 && arr2.length == 0) return arr1
	else {
		//合并两个数组
		arr1.push(...arr2) //或者arr1 = [...arr1,...arr2]
		//去重
		let arr3 = Array.from(new Set(arr1)) //let arr3 = [...new Set(arr1)]
		return arr3
	}
}

//全局方法-比较时间
Vue.prototype.$compareT = function(param1, param2) {
	let time1 = new Date(param1).getTime();
	let time2 = new Date(param2).getTime();
	if (time2 > time1) {
		return true
	} else {
		return false
	}
};

let fullFn = function(time) {
	if (time < 10) {
		return '0' + time
	} else {
		return time
	}
}
//全局方法-获取当前时间
Vue.prototype.$getNowDate = function(param, defaultTime) {
	let time = new Date();
	if (defaultTime) {
		time = new Date(defaultTime)
	}
	let year = time.getFullYear();
	let month = fullFn(time.getMonth() + 1);
	let date = fullFn(time.getDate());
	let hours = fullFn(time.getHours());
	let minutes = fullFn(time.getMinutes());
	if (param == 'dateTime') {
		return year + '-' + month + '-' + date + 'T' + hours + ':' + minutes;
	} else if (param == 'time') {
		return hours + ':' + minutes;
	} else if (param == 'date') {
		return year + '-' + month + '-' + date;
	}
}

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>'
})
